﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OgilvyOne.Borad.BLL;

public partial class action_preorder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PreOrderBLL bll = new PreOrderBLL();
        PostAPI PostBll = new PostAPI();
        string op = Request.QueryString["op"];
        string name = Server.UrlDecode(Request.QueryString["name"]);
        string sex = Server.UrlDecode(Request.QueryString["sex"]);
        string mobile = Server.UrlDecode(Request.QueryString["mobile"]);
        string email = Server.UrlDecode(Request.QueryString["email"]);
        string province = Server.UrlDecode(Request.QueryString["province"]);
        string city = Server.UrlDecode(Request.QueryString["city"]);
        string dealer = Server.UrlDecode(Request.QueryString["dealer"]);
        string budget = Server.UrlDecode(Request.QueryString["budget"]);
        string mention = Server.UrlDecode(Request.QueryString["mention"]);
        string capcity = Server.UrlDecode(Request.QueryString["capcity"]);
        string carModel = Server.UrlDecode(Request.QueryString["carModel"]);
        string carColor = Server.UrlDecode(Request.QueryString["carColor"]);
        string carSeat = Server.UrlDecode(Request.QueryString["carSeat"]);
        string source = Server.UrlDecode(Request.QueryString["source"]);
        string img = Server.UrlDecode(Request.QueryString["img"]);
        string channel = Server.UrlDecode(Request.QueryString["channel"]);
        //int provinceValue=0;
        //int cityValue = 0;
        //int dealerValue = 0;
        string provinceValue="";
        string cityValue="";
        string dealerValue="";
        if (!string.IsNullOrEmpty(Request.QueryString["provinceValue"]))
            provinceValue = Server.UrlDecode(Request.QueryString["provinceValue"]);
        if (!string.IsNullOrEmpty(Request.QueryString["cityValue"]))
            cityValue = Server.UrlDecode(Request.QueryString["cityValue"]);
        if (!string.IsNullOrEmpty(Request.QueryString["dealerValue"]))
            dealerValue = Server.UrlDecode(Request.QueryString["dealerValue"]);
        string output = "";

        //if (carColor == "金属漆_礁石蓝")
        //{
        //    if (capcity == "1.4TSI")
        //    {
        //        if (carModel == "时尚型")
        //            carSeat = "";
        //    }
        //}

        //正式服api
        string apiAddress = "http://vico1.vw.com.cn/newcms/testdrive/api/regsave.aspx";
        //测试服api
        //string apiAddress = "http://vico.ogilvy.com.cn/newcms/testdrive/api/regsave.aspx";
        if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(sex) && !string.IsNullOrEmpty(mobile) && !string.IsNullOrEmpty(email))
        {
            switch (op)
            {
                case "reg":
                    output = Insert(bll, img, name, sex, mobile, email, province, city, dealer, budget, mention, capcity, carModel, carColor, carSeat, source, channel);
                    try
                    {
                        post(PostBll, name, sex, mobile, email, provinceValue, cityValue, dealerValue, mention, budget, source, capcity, carModel, carColor, carSeat, channel, apiAddress);
                    }
                    catch (Exception ex)
                    {
                        break;
                    }
                    break;
                case "isExist":
                    output = isExist(bll, email);
                    break;
            }
        }
        Response.Write(output);
    }

    public string Insert(PreOrderBLL bll, string img, string name,string sex, string mobile, string email, string province, string city, string dealer, string budget, string mention, string capcity, string carModel, string carColor, string carSeat, string source,string channel) 
    {
        return bll.Insert(img, name, sex, mobile, email, province, city, dealer, budget, mention, capcity, carModel, carColor, carSeat, source,channel).ToString();
    }

    public string isExist(PreOrderBLL bll,string email)
    {
        return bll.IsExist(email).ToString();
    }

    public string post(PostAPI bll, string username, string sex, string mobile, string email, string dealerprovince, string dealercity, string dealer, string buytime, string buybudget, string source, string Displacement, string CarModel, string CarColor, string CarSeat, string channel,string apiAddress)
    {
        return bll.Save(username, sex, mobile, email, dealerprovince, dealercity, dealer, buytime, buybudget, source, Displacement, CarModel, CarColor, CarSeat, channel, apiAddress);
    }
}